﻿using Microsoft.EntityFrameworkCore;
using swiftCode.Bbs.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Repositories.EfContext
{
    public class SwiftCodeBbsContext : DbContext
    {
        public SwiftCodeBbsContext() 
        {
            
        }

        public SwiftCodeBbsContext(DbContextOptions<SwiftCodeBbsContext> options) : base(options)
        {
            
        }

        //public DbSet<Article> Articles { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<Post> Posts { get; set; }
        public DbSet<Module> Modules { get; set; }
        public DbSet<BanRecord> BanRecords { get; set; }
        public DbSet<Reply> replies { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.Entity<Article>().Property(p => p.Title).HasMaxLength(200);
            //modelBuilder.Entity<Article>().Property(p => p.Submitter).HasMaxLength(50);
            //modelBuilder.Entity<Article>().Property(p => p.Category).HasMaxLength(100);
            //modelBuilder.Entity<Article>().Property(p => p.Content).HasMaxLength(2000);
            //modelBuilder.Entity<Article>().Property(p => p.Remark).HasMaxLength(200);
            //modelBuilder.Entity<Comment>().Property(p => p.Content).HasMaxLength(200);
            //modelBuilder.Entity<Comment>().Property(p => p.Submitter).HasMaxLength(50);
            //modelBuilder.Entity<Comment>().Property(p => p.Remark).HasMaxLength(1000);

            modelBuilder.Entity<User>().Property(p => p.UserName).HasMaxLength(50);
            modelBuilder.Entity<User>().Property(p => p.Password).HasMaxLength(10);
            modelBuilder.Entity<User>().Property(p => p.AvatarPath).HasMaxLength(50);
            modelBuilder.Entity<User>().Property(p => p.Role).HasDefaultValue(2);

            modelBuilder.Entity<Role>().Property(p => p.RoleName).HasMaxLength(10);

            modelBuilder.Entity<Post>().Property(p => p.Title).HasMaxLength(50);
            modelBuilder.Entity<Post>().Property(p => p.content).HasMaxLength(100000);
            modelBuilder.Entity<Post>().Property(p => p.picture).HasMaxLength(255);
            modelBuilder.Entity<Post>().Property(p => p.postTime).HasColumnType("DATETIME").HasDefaultValueSql("NOW()");

            modelBuilder.Entity<Module>().Property(p => p.ModuleName).HasMaxLength(20);

            modelBuilder.Entity<BanRecord>().Property(p => p.reason).HasMaxLength(255);

            modelBuilder.Entity<Reply>().Property(p => p.ReplyContent).HasMaxLength(255);
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySQL("server=101.35.249.217;database=forumsystem;user=root;password=whx1004;Port=3307;");
        }
    }
}
